#ifndef  __ANY_H__
#define __ANY_H__
#include <memory>
#include "Nocopyable.hpp"
/*
 *接受任意类型包装类
 * */
class Any :public Nocopyable
{
public:
    Any()=default;
    ~Any()=default;
    Any(Any &&)=default;
    Any& operator=(Any &&)=default;
    template<typename T>
        Any(T data);
    template<typename T>
        T cast_();
private:
    class Base{
    public:
        virtual ~Base()=default;
    };
    template<typename T>
        class Derive:public Base{
        friend class Any;
        public:
            Derive(T data);
        private:
            T data_;
        };
    std::unique_ptr<Base> base_;
};


template<typename T>
Any::Any(T data)
    :base_(std::make_unique<Derive<T>>(data))
{

}

template<typename T>
Any::Derive<T>::Derive(T data):data_(data){

}
template<typename T>
T Any::cast_(){
    Derive<T> * derive=dynamic_cast<Derive<T>*>(base_.get());
    if(derive==nullptr){
        throw "type is unmatch";
    }
    return derive->data_;
}
#endif
